package commands;

import java.io.PrintWriter;

import server.AccessDeniedException;
import server.RefrensMonitor;
import server.Subject;

public class WriteAction implements Action {
	private PrintWriter pw;
	private Subject sub;
	private String message;
	public WriteAction(PrintWriter pw, Subject sub, String string) {
		this.pw = pw;
		this.sub = sub;
		this.message = string;
	}

	@Override
	public void perform() {
		String[] args = message.split(" ", 2);
		int record = 0;
		try{
			record = Integer.parseInt(args[0]);
		}
		catch (NumberFormatException e){
			pw.println("Argument error");
		}
		try {
			RefrensMonitor.getInstance().write(sub, record, args[1]);
		} catch (AccessDeniedException e) {
			pw.println("Access Denied");
		}
	}

}
